package com.thoughtworks.mobinium.android;

import java.lang.reflect.Field;

public final class AndroidHelper {

	public static int getResourceIdForControlByName(
			String fullyQualifiedResourceClassName, String name) {
		try {
			Class clazz = Class
					.forName(fullyQualifiedResourceClassName + "$id");
			Field[] fields = clazz.getFields();
			for (Field field : fields) {
				if (field.getName().equals(name)) {
					return field.getInt(null);
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
		throw new RuntimeException("No such resource:" + name);
	}
}
